package com.xinshujia.wxxcx.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.xinshujia.wxxcx.service.WxUserService;
import com.xinshujia.wxxcx.util.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Cui Han
 * @Date 2024/4/27 13:51
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/wxUser")
public class WxUserController {

    @Autowired
    private WxUserService wxUserService;

    /**
     * 登录
     * @param phone
     * @param password
     * @return
     */
    @GetMapping("/login")
    public Result login(String phone, String password) {
        return wxUserService.login(phone, password);
    }


    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("WxUserInfo")
    @SaCheckLogin
    public Result userInfo() {
       return Result.ok(wxUserService.getUserInfo());
    }


    /**
     * 退出登录
     * @return
     */
    @GetMapping ("logout")
    public Result logout() {
        StpUtil.logout();
        return Result.ok("退出成功");
    }
}